package graduationorder.graduationorder.controller;

import graduationorder.graduationorder.domain.Order;
import graduationorder.graduationorder.error.BusinessException;
import graduationorder.graduationorder.handler.GlobalExceptionHandler;
import graduationorder.graduationorder.result.CommonReturnType;
import graduationorder.graduationorder.service.impl.OrdersServiceimpl;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
@RestController
@RequestMapping("/order")
public class OrdersController extends GlobalExceptionHandler {

    @Resource
    private OrdersServiceimpl ordersServiceimpl;

    @PostMapping("/create_order")
    public CommonReturnType createOrder(@RequestBody Order order) throws BusinessException {
        return ordersServiceimpl.createOrder(order);
    }

    @GetMapping("/get_order_all")
    public CommonReturnType getOrderAll(){
        return ordersServiceimpl.getAllOrdersmapper();
    }

    @GetMapping("/get_order/{orderId}")
    public CommonReturnType getOrderById(@PathVariable("orderId") String orderId){
        return ordersServiceimpl.getOrders(orderId);
    }

    @PostMapping("/status")// /{orderId}/status
    public CommonReturnType updateOrder(@RequestBody Order order) throws BusinessException {
        return ordersServiceimpl.updateOrder(order);
    }

    @PostMapping("/delete")
    public CommonReturnType deleteOrder(String orderId) throws BusinessException {
        return ordersServiceimpl.deleteOrder(orderId);
    }



}
